#============================================================
#	Mouse Hover Scale
#============================================================
#  鼠标悬停缩放
# * 注意设置父节点的 "rect_pivot_offset" 属性，设置为这个 Control 
#     类型节点大小的一半的 rect_pivot_offset 属性，则在缩放时居中缩放
#============================================================
# @datetime: 2022-5-13 02:56:30
#============================================================
extends Node


export var scale_to : Vector2 = Vector2(1.5, 1.5)
export var duration : float = 1.0


var host : Control
var tween : Tween = Tween.new()
var origin_scale : Vector2

func _ready():
	add_child(tween)
	var node = get_parent()
	if node is Control:
		host = node
		origin_scale = host.rect_scale
		node.connect("mouse_entered", self, "mouse_entered")
		node.connect("mouse_exited", self, "mouse_exited")


var trans = Tween.TRANS_ELASTIC

func mouse_entered():
	tween.interpolate_property(
		host, "rect_scale",
		host.rect_scale, scale_to, duration
		, trans, Tween.EASE_OUT
	)
	tween.start()


func mouse_exited():
	tween.stop_all()
	tween.interpolate_property(
		host, "rect_scale",
		host.rect_scale, origin_scale, duration
		, trans, Tween.EASE_OUT
	)
	tween.start()
